//
//  StarView.m
//  项目一TimeMovie
//
//  Created by apple on 16/3/30.
//  Copyright © 2016年 huangmingyu. All rights reserved.
//

#import "StarView.h"

@implementation StarView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.height = kScreenWidth / 14;
        [self creatSubViews];
        self.backgroundColor = [UIColor clearColor];
        
    }
    return self;
}

- (void)awakeFromNib {
    
    [super awakeFromNib];
//    self.height = kScreenWidth / 14;
    [self creatSubViews];
    self.backgroundColor = [UIColor clearColor];
}


- (void)creatSubViews {
    
    grayView = [[UIView alloc] init];
    yellowView = [[UIView alloc] init];
    [self addSubview:grayView];
    [self addSubview:yellowView];
    
    
    UIImage *image = [UIImage imageNamed:@"yellow"];
    float scale = self.height / (image.size.height + 0.5);
    
    grayView.transform = CGAffineTransformMakeScale(scale, scale);
    yellowView.transform = CGAffineTransformMakeScale(scale, scale);
    
    grayView.frame = CGRectMake(0, 0, 5 * self.height, self.height);
    grayView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"gray"]];
    
    yellowView.frame = CGRectMake(0, 0, 5 * self.height, self.height);
    yellowView.backgroundColor = [UIColor colorWithPatternImage:image];
    
    
    
    
}

- (void)changeStarViewWithRating:(float)rating {
    
    yellowView.frame = CGRectMake(0, 0, 5 * self.height * rating / 10, self.height);
    
}

@end
